package ysq.xyg.web.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.sys.service.SysUserService;
import ysq.xyg.web.model.po.WebArea;
import ysq.xyg.web.model.po.WebAreaUser;
import ysq.xyg.web.model.vo.WebAreaUserVo;
import ysq.xyg.web.service.WebAreaService;
import ysq.xyg.web.service.WebAreaUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 业务模块-活动室预约人员controller层
 *
 * @author shengQiang yu
 * @date 2019-5-15 22:39:34
 */
@RestController
public class WebAreaUserController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(WebAreaUserController.class);
    @Resource
    private SysUserService sysUserService;
    @Resource
    private WebAreaService webAreaService;
    @Resource
    private WebAreaUserService webAreaUserService;

    private WebAreaUser webAreaUser;

    /**
     * 分页查询
     *
     * @param webAreaUserVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-5-15 22:39:34
     */
    @BaseLog(module = "业务模块",className = "活动室预约人员",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webAreaUser/page",method = RequestMethod.POST)
    public ReturnEntity page(HttpServletRequest request, WebAreaUserVo webAreaUserVo, int pageSize, int pageNum){
        SysUser sysUser = acceptCurrentUser(request);
        sysUser=sysUserService.selectByPrimaryKey(sysUser.getId());
        if(BaseConstant.BASE_USER_TYPE_GLY.equals(sysUser.getUserType())){
            webAreaUserVo.setUserId(sysUser.getId());
        }
        ReturnEntity returnEntity = webAreaUserService.page(webAreaUserVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-15 22:39:34
     */
    @RequestMapping(value = "/webAreaUser/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/web/webAreaUserUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            webAreaUser = webAreaUserService.selectByPrimaryKey(id);
            view.addObject("webAreaUser", webAreaUser);
            if(webAreaUser!=null){
                WebArea webArea=webAreaService.selectByPrimaryKey(webAreaUser.getAreaId());
                view.addObject("webArea", webArea);
            }
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-5-15 22:39:34
     */
    @BaseLog(module = "业务模块",className = "活动室预约人员",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webAreaUser/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return webAreaUserService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param webAreaUserVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-15 22:39:34
     */
    @BaseLog(module = "业务模块",className = "活动室预约人员",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/webAreaUser/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,WebAreaUserVo webAreaUserVo){
        return webAreaUserService.addOrUpdate(webAreaUserVo,acceptCurrentUser(request));
    }
    /**
     * 导出
     *
     * @param webAreaUserVo Vo对象
     * @author shengQiang yu
     * @date 2019-5-11 10:02:08
     */
    @RequestMapping(value = "/webAreaUser/export",method = RequestMethod.POST)
    public void export(HttpServletResponse response,WebAreaUserVo webAreaUserVo){
        webAreaUserService.export(response,webAreaUserVo);
    }
}